using System.Collections.Generic;
using SimpleJSON;
using UnityEngine;

namespace Game.Main.Model
{
	public class ItemArchiveData
	{
		public uint index;

		public int mapId;

		public float x;

		public float y;

		public int layer;

		public int dirX;

		public List<ChildNodeData> frontNodes;

		public List<ChildNodeData> aheadNodes;

		public List<ChildNodeData> behindNodes;

		public List<ChildNodeData> backNodes;

		public bool forceStand;

		public uint createParentIndex;

		public List<uint> createIndexs = new List<uint>();

		public ItemData itemData;

		public float floatValue;

		public float floatY;

		public float floatRange;

		public float waterY;

		public float waterHeight;

		public byte inElevator;

		public float localX;

		public float localY;

		public bool resetPlace;

		public float placeX;

		public float placeY;

		public uint putParentItemIndex;

		public int putParentItemAttachType;

		public int putParentItemDepthType;

		public int headId;

		public int hairId;

		public int bodyId;

		public int topsId;

		public int topsIconId;

		public int pantsId;

		public int shoesId;

		public int browId;

		public int eyeId;

		public int noseId;

		public int mouthId;

		public int featureId;

		public Color32 hairColor;

		public Color32 bodyColor;

		public float mapX;

		public float mapY;

		public int state;

		public int intParam1;

		public int intParam2;

		public float floatParam1;

		public float floatParam2;

		public float modelX;

		public float modelY;

		public Color32 color;

		public List<int> intList;

		public string pixels;

		public void PackData(JSONObject obj)
		{
			obj["0"] = index;
			obj["54"] = mapId;
			obj["1"] = itemData.id;
			obj["2"] = x.ToString("F5");
			obj["3"] = y.ToString("F5");
			obj["4"] = layer;
			obj["5"] = dirX;
			if (floatValue != 0f)
			{
				obj["49"] = floatValue.ToString("F2");
			}
			if (floatY != 0f)
			{
				obj["50"] = floatY.ToString("F2");
			}
			if (floatRange != 0f)
			{
				obj["51"] = floatRange.ToString("F2");
			}
			if (waterHeight != 0f)
			{
				obj["52"] = waterHeight.ToString("F4");
			}
			if (waterY != 0f)
			{
				obj["53"] = waterY.ToString("F5");
			}
			if (createParentIndex != 0)
			{
				obj["6"] = createParentIndex;
			}
			if (createIndexs.Count > 0)
			{
				obj["7"] = PackUIntList(createIndexs);
			}
			if (forceStand)
			{
				obj["8"] = forceStand;
			}
			if (frontNodes != null && frontNodes.Count > 0)
			{
				obj["9"] = PackNodeData(frontNodes);
			}
			if (aheadNodes != null && aheadNodes.Count > 0)
			{
				obj["10"] = PackNodeData(aheadNodes);
			}
			if (behindNodes != null && behindNodes.Count > 0)
			{
				obj["11"] = PackNodeData(behindNodes);
			}
			if (backNodes != null && backNodes.Count > 0)
			{
				obj["12"] = PackNodeData(backNodes);
			}
			obj["57"] = localX.ToString("F5");
			obj["58"] = localY.ToString("F5");
			SetJsonObject(obj, "13", headId);
			SetJsonObject(obj, "14", hairId);
			SetJsonObject(obj, "15", bodyId);
			SetJsonObject(obj, "16", topsId);
			SetJsonObject(obj, "17", topsIconId);
			SetJsonObject(obj, "18", pantsId);
			SetJsonObject(obj, "19", shoesId);
			SetJsonObject(obj, "20", browId);
			SetJsonObject(obj, "21", eyeId);
			SetJsonObject(obj, "23", mouthId);
			SetJsonObject(obj, "55", featureId);
			SetJsonObject(obj, "24", hairColor.r);
			SetJsonObject(obj, "25", hairColor.g);
			SetJsonObject(obj, "26", hairColor.b);
			SetJsonObject(obj, "27", bodyColor.r);
			SetJsonObject(obj, "28", bodyColor.g);
			SetJsonObject(obj, "29", bodyColor.b);
			SetJsonObject(obj, "33", state);
			SetJsonObject(obj, "59", intParam1);
			SetJsonObject(obj, "60", intParam2);
			SetJsonObject(obj, "62", floatParam1);
			SetJsonObject(obj, "63", floatParam2);
			SetJsonObject(obj, "34", modelX);
			SetJsonObject(obj, "39", modelY);
			SetJsonObject(obj, "30", color.r);
			SetJsonObject(obj, "31", color.g);
			SetJsonObject(obj, "32", color.b);
			SetJsonObject(obj, "64", mapX);
			SetJsonObject(obj, "65", mapY);
			SetJsonObject(obj, "66", resetPlace ? 1 : 0);
			SetJsonObject(obj, "67", placeX);
			SetJsonObject(obj, "68", placeY);
			SetJsonObject(obj, "69", putParentItemIndex);
			SetJsonObject(obj, "70", putParentItemAttachType);
			SetJsonObject(obj, "71", putParentItemDepthType);
			if (intList != null && intList.Count > 0)
			{
				obj["48"] = PackIntList(intList);
			}
			if (!string.IsNullOrEmpty(pixels))
			{
				obj["61"] = pixels;
			}
		}

		private void SetJsonObject(JSONObject obj, string name, int val)
		{
			if (val != 0)
			{
				obj[name] = val;
			}
		}

		private void SetJsonObject(JSONObject obj, string name, float val)
		{
			if (val != 0f)
			{
				obj[name] = val;
			}
		}

		private string PackUIntList(List<uint> list)
		{
			if (list.Count <= 0)
			{
				return string.Empty;
			}
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				text = text + list[i] + ",";
			}
			return text.Substring(0, text.Length - 1);
		}

		private string PackIntList(List<int> list)
		{
			if (list.Count <= 0)
			{
				return string.Empty;
			}
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				text = text + list[i] + ",";
			}
			return text.Substring(0, text.Length - 1);
		}

		private string PackNodeData(List<ChildNodeData> list)
		{
			string text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				string text2 = text;
				text = text2 + list[i].index + "," + list[i].attachType + "|";
			}
			return text.Substring(0, text.Length - 1);
		}
	}
}
